package com.lanxin.jet.services;

import java.util.List;

import javax.servlet.http.HttpSession;

import com.lanxin.jet.beans.UserBean;
import com.lanxin.jet.beans.UserTokenBean;

public interface UserService {

    public final static int STATUS_LOCK     = 0; //冻结
    public final static int STATUS_NORMAL   = 1; //普通用户
    public final static int STATUS_VIP      = 2; //会员
    public final static int STATUS_ADMIN    = 9; //管理员

    public final static int ROLE_CONTENT    = 1; //权限 - 内容
    public final static int ROLE_RESOURCE   = 2; //权限 - 资源
    public final static int ROLE_USER       = 4; //权限 - 用户
    public final static int ROLE_SUPER      = 8; //权限 - 特需

    //标准CURD
    public UserTokenBean add(String account, String password, String name, String ip);
    public int count(int status, String keyword);
    public UserBean get(String id);
    public List<UserBean> getList(int offset, int limit, int status, String keyword);
    public void update(UserBean user);
    public void delete(String id);

    /**
     * 通过账号查找用户
     * @param account
     * @return
     */
    public UserBean getAccount(String account);

    /**
     * 检测账户是否存在
     * @param account   用户账号
     * @return
     */
    public boolean existAccount(String account);

    /**
     * 构建用户令牌
     * @param uid   用户id
     * @param ip    客户端ip地址
     * @param count 登录次数
     * @return
     */
    public UserTokenBean buildToken(UserBean user, String ip);

    /**
     * 验证用户令牌
     * @param userToken 用户令牌
     */
    public boolean checkToken(UserTokenBean userToken);


    /**
     * 验证用户权限
     * @param session   会话
     * @param role      权限
     * @return
     */
    public boolean checkRole(HttpSession session, int role);

}